import requests
from bs4 import BeautifulSoup


class WeiboHot:
    def __init__(self):
        self.platform = "weibo"
        self.url = "https://s.weibo.com/top/summary"

    def fetch(self):
        headers = {
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36...'
        }
        resp = requests.get(self.url, headers=headers)
        soup = BeautifulSoup(resp.text, 'html.parser')

        hotspots = []
        for item in soup.select('#pl_top_realtimehot table tr'):
            title = item.select_one('td a').text
            hot = item.select_one('td span').text
            hotspots.append({
                'title': title,
                'hot': hot,
                'url': f"https://s.weibo.com/{item.select_one('a')['href']}"
            })
        return hotspots[:10]  # 取前10条

    if __name__ == '__main__':
        fetch('PyCharm')